/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditTransactionRelease.java
 *
 * Created on Nov 8, 2011, 1:26:29 AM
 */
package mpinventory;

import java.beans.PropertyVetoException;
import java.sql.*;
import java.util.List;
import java.util.ArrayList;
import com.michaelbaranov.microba.calendar.DatePicker;
import java.util.Calendar;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.DefaultListModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
 *
 * @author msi
 */
public class EditTransactionRelease extends javax.swing.JPanel {

    private Connection conn;
    private Dimension size;
    private DateFormat dateFormat=new SimpleDateFormat("MMMM dd, yyyy");
    private Calendar calendar=Calendar.getInstance();
    private Date date=new Date(calendar.get(calendar.YEAR)-1900,calendar.get(calendar.MONTH),calendar.get(calendar.DAY_OF_MONTH));
    private DatePicker datePicker=new DatePicker(date,dateFormat);
    public TransactionReleaseQuery releaseQuery;
    private InstallationQuery installationQuery;
    private List<Installation> installations;
    public int width;
    public int height;
    public int screenWidth;
    public int screenHeight;
    private int selectedIndex;
    private int nRows=0;
    private int customerID;
    public boolean backToMainMenu=false;
    private DefaultTableModel model;
    private String data[][] = {};
    private String col[] = {"Serial Number", "Brand", "Model", "Quantity", "Price"};

    private List<String> origSerialNumbers;
    private List<String> serialNumbers;
    private List<String> brands;
    private List<String> models;
    private List<Integer> installationIDs;
    private List<Integer> quantities;
    private List<Float> prices;
    /** Creates new form EditTransactionRelease */
    public EditTransactionRelease(Connection conn, int screenWidth, int screenHeight, int orderID, int customerID, String customerName, Date orderDate, String orderStatus, List<String> serialNumbers, List<Integer> quantities, List<Float> prices, List<Integer> installationIDs, List<String> brands, List<String> models) throws PropertyVetoException {
        this.conn=conn;
        this.screenWidth=screenWidth;
        this.screenHeight=screenHeight;
        myInitComponents();
        size=this.getPreferredSize();
        width=size.width;
        height=size.height+35;
        releaseQuery=new TransactionReleaseQuery(conn);
        txtTREOrderID.setText(orderID+"");
        this.customerID=customerID;
        txtTRECustomer.setText(customerName);
        datePicker.setDate(orderDate);
        date=orderDate;
        cbxTREStatus.setSelectedItem(orderStatus);
        origSerialNumbers=serialNumbers;
        this.serialNumbers=serialNumbers;
        this.installationIDs=installationIDs;
        this.quantities=quantities;
        this.prices=prices;
        this.brands=brands;
        this.models=models;
        model = new DefaultTableModel(data, col){
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Float.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, true, true
            };
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        };
        tableTRECustomerOrders.setModel(model);
        tableTRECustomerOrders.getColumnModel().getColumn(0).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(0).setPreferredWidth(120);
        tableTRECustomerOrders.getColumnModel().getColumn(1).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(1).setPreferredWidth(100);
        tableTRECustomerOrders.getColumnModel().getColumn(2).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(2).setPreferredWidth(95);
        tableTRECustomerOrders.getColumnModel().getColumn(3).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(3).setPreferredWidth(10);
        tableTRECustomerOrders.getColumnModel().getColumn(4).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(4).setPreferredWidth(50);
        initializeInstallationList();
        try{
        for(int i=0; i<installationIDs.size();i++){
            Object[] rowData=new Object[5];
            rowData[0]=serialNumbers.get(i);
            rowData[1]=brands.get(i);
            rowData[2]=models.get(i);
            rowData[3]=quantities.get(i);
            rowData[4]=prices.get(i);
            model.insertRow(nRows,rowData);
            nRows++;
        }
        }catch(Exception e){}
        tableTRECustomerOrders.setModel(model);
    }
    @Override
    public int getWidth(){
        return width;
    }
    @Override
    public int getHeight(){
        return height;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        cbxTREBrand = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listTREUnits = new javax.swing.JList();
        btnTRERemove = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        btnTREAdd = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        txtTREOrderID = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        cbxTREStatus = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        btnTRESave = new javax.swing.JButton();
        btnTRECancel = new javax.swing.JButton();
        txtTRECustomer = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableTRECustomerOrders = new javax.swing.JTable();

        setPreferredSize(new java.awt.Dimension(1200, 450));
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 25));
        jLabel1.setText("Edit Customer Transaction");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 10, -1, -1));

        cbxTREBrand.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 15));
        cbxTREBrand.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Carrier" }));
        add(cbxTREBrand, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 150, 222, -1));

        jLabel10.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel10.setText("Add to -------------->");
        add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 240, -1, -1));

        jLabel8.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel8.setText("List of Air-Conditioning Unit Models:");
        add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 200, -1, -1));

        listTREUnits.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 15));
        listTREUnits.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "FP-42CVSR016", "WCARP24EA", "WCARG010EC DLX" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(listTREUnits);

        add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 240, 242, 146));

        btnTRERemove.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        btnTRERemove.setText("Remove");
        btnTRERemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeModelActionPerformed(evt);
            }
        });
        add(btnTRERemove, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 360, -1, -1));

        jLabel11.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel11.setText("Customer Orders:");
        add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 200, -1, -1));

        btnTREAdd.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        btnTREAdd.setText("Add");
        btnTREAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addModelActionPerformed(evt);
            }
        });
        add(btnTREAdd, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 270, 96, -1));

        jLabel9.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel9.setText("Remove from ----->");
        add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 320, -1, -1));

        txtTREOrderID.setEditable(false);
        txtTREOrderID.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 15));
        add(txtTREOrderID, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 70, 117, -1));

        jLabel3.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel3.setText("Order ID:");
        add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, -1, -1));

        jLabel4.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel4.setText("Status:");
        add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 110, -1, -1));

        jLabel5.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel5.setText("Customer:");
        add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 120, -1, -1));

        cbxTREStatus.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 15));
        cbxTREStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pending", "Delivered" }));
        add(cbxTREStatus, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 110, 222, -1));

        jLabel6.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel6.setText("Date:");
        add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 70, -1, -1));

        jLabel12.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel12.setText("Brand:");
        add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 150, -1, -1));

        btnTRESave.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        btnTRESave.setText("Save");
        btnTRESave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveActionPerformed(evt);
            }
        });
        add(btnTRESave, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 400, 96, -1));

        btnTRECancel.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        btnTRECancel.setText("Cancel");
        btnTRECancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });
        add(btnTRECancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 400, 96, -1));

        txtTRECustomer.setEditable(false);
        txtTRECustomer.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 15));
        add(txtTRECustomer, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 120, 280, -1));

        tableTRECustomerOrders.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Serial Number", "Brand", "Model", "Quantity", "Price"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Float.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableTRECustomerOrders.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(tableTRECustomerOrders);
        tableTRECustomerOrders.getColumnModel().getColumn(0).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(0).setPreferredWidth(120);
        tableTRECustomerOrders.getColumnModel().getColumn(1).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(1).setPreferredWidth(100);
        tableTRECustomerOrders.getColumnModel().getColumn(2).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(2).setPreferredWidth(95);
        tableTRECustomerOrders.getColumnModel().getColumn(3).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(3).setPreferredWidth(10);
        tableTRECustomerOrders.getColumnModel().getColumn(4).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(4).setPreferredWidth(50);

        add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 240, 685, 146));
    }// </editor-fold>//GEN-END:initComponents
private void myInitComponents(){
        jLabel1 = new javax.swing.JLabel();
        cbxTREBrand = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listTREUnits = new javax.swing.JList();
        btnTRERemove = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        btnTREAdd = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        txtTREOrderID = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        cbxTREStatus = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        btnTRESave = new javax.swing.JButton();
        btnTRECancel = new javax.swing.JButton();
        txtTRECustomer = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableTRECustomerOrders = new javax.swing.JTable();

        setPreferredSize(new java.awt.Dimension(1200, 450));
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 25));
        jLabel1.setText("Edit Customer Transaction");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 10, -1, -1));

        cbxTREBrand.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 15));
        cbxTREBrand.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Carrier" }));
        add(cbxTREBrand, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 150, 222, -1));

        jLabel10.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel10.setText("Add to -------------->");
        add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 240, -1, -1));

        jLabel8.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel8.setText("List of Air-Conditioning Unit Models:");
        add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 200, -1, -1));

        listTREUnits.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 15));
        listTREUnits.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "FP-42CVSR016", "WCARP24EA", "WCARG010EC DLX" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(listTREUnits);

        add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 240, 242, 146));

        btnTRERemove.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        btnTRERemove.setText("Remove");
        btnTRERemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeModelActionPerformed(evt);
            }
        });
        add(btnTRERemove, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 360, -1, -1));

        jLabel11.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel11.setText("Customer Orders:");
        add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 200, -1, -1));

        btnTREAdd.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        btnTREAdd.setText("Add");
        btnTREAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addModelActionPerformed(evt);
            }
        });
        add(btnTREAdd, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 270, 96, -1));

        jLabel9.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel9.setText("Remove from ----->");
        add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 320, -1, -1));

        txtTREOrderID.setEditable(false);
        txtTREOrderID.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 15));
        add(txtTREOrderID, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 70, 117, -1));

        jLabel3.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel3.setText("Order ID:");
        add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, -1, -1));

        jLabel4.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel4.setText("Status:");
        add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 110, -1, -1));

        jLabel5.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel5.setText("Customer:");
        add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 120, -1, -1));

        cbxTREStatus.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 15));
        cbxTREStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pending", "Delivered" }));
        add(cbxTREStatus, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 110, 222, -1));

        jLabel6.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel6.setText("Date:");
        add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 70, -1, -1));

        jLabel12.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        jLabel12.setText("Brand:");
        add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 150, -1, -1));

        btnTRESave.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        btnTRESave.setText("Save");
        btnTRESave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveActionPerformed(evt);
            }
        });
        add(btnTRESave, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 400, 96, -1));

        btnTRECancel.setFont(new java.awt.Font("Arial Rounded MT Bold", 1, 15));
        btnTRECancel.setText("Cancel");
        btnTRECancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });
        add(btnTRECancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 400, 96, -1));

        txtTRECustomer.setEditable(false);
        txtTRECustomer.setFont(new java.awt.Font("Arial Rounded MT Bold", 0, 15));
        add(txtTRECustomer, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 120, 280, -1));

        tableTRECustomerOrders.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Serial Number", "Brand", "Model", "Quantity", "Price"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Float.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableTRECustomerOrders.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(tableTRECustomerOrders);
        tableTRECustomerOrders.getColumnModel().getColumn(0).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(0).setPreferredWidth(120);
        tableTRECustomerOrders.getColumnModel().getColumn(1).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(1).setPreferredWidth(100);
        tableTRECustomerOrders.getColumnModel().getColumn(2).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(2).setPreferredWidth(95);
        tableTRECustomerOrders.getColumnModel().getColumn(3).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(3).setPreferredWidth(10);
        tableTRECustomerOrders.getColumnModel().getColumn(4).setResizable(false);
        tableTRECustomerOrders.getColumnModel().getColumn(4).setPreferredWidth(50);

        add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 240, 685, 146));

        datePicker.setShowNumberOfWeek(true);
        datePicker.setShowNoneButton(false);
        datePicker.setFieldEditable(false);
        add(datePicker, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 70, -1, -1));
}
    private void initializeInstallationList(){
        installationQuery=new InstallationQuery(conn);
        installations=installationQuery.initializeInstallations();
        cbxTREBrand.removeAllItems();
        ArrayList<String> temp=new ArrayList<String>();
        for(int i=0;i<installations.size();i++)
            if(!temp.contains(installations.get(i).getBrand())){
                cbxTREBrand.addItem(installations.get(i).getBrand());
                temp.add(installations.get(i).getBrand());
            } //assures no duplicate brands will appear in dropdown list
        installations=installationQuery.search(installations.get(0).getBrand());
        cbxTREBrand.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent actionEvent){
                try{
                    installations=installationQuery.search(cbxTREBrand.getSelectedItem().toString());
                }catch(Exception e){}
                DefaultListModel listModel = new DefaultListModel();
                try{
                    for(int i=0;i<installations.size();i++)
                        listModel.addElement(installations.get(i).getModel());
                    listTREUnits.setModel(listModel);
                }catch(Exception e){
                    installations=installationQuery.initializeInstallations();
                    for(int i=0;i<installations.size();i++)
                        listModel.addElement(installations.get(i).getModel());
                    listTREUnits.setModel(listModel);
                }
            }
        });
        DefaultListModel listModel = new DefaultListModel();
        for(int i=0;i<installations.size();i++)
            listModel.addElement(installations.get(i).getModel());
        listTREUnits.setModel(listModel);
    } //end of initializeInstallationList() method
    private boolean validTable(){
        for(int i=0;i<model.getRowCount();i++)
            for(int j=0;j<model.getColumnCount();j++)
                try{
                    if(model.getValueAt(i,j).equals(null))
                        return false;
                }catch(NullPointerException e){
                    return false;
                }
        return true;
    } //end of validTable() method
    private boolean tableIsEmpty(){
        for(int i=0;i<model.getRowCount();i++)
            for(int j=0;j<model.getColumnCount();j++)
                try{
                    if(!model.getValueAt(i,j).toString().isEmpty())
                        return false;
                }catch(NullPointerException e){
                    return false;
                }
        return true;
    } //end of tableIsEmpty() method
    private void getTableValues(){
        brands=new ArrayList<String>();
        models=new ArrayList<String>();
        quantities=new ArrayList<Integer>();
        prices=new ArrayList<Float>();
        String[] rowData=new String[model.getColumnCount()];
        for(int i=0;i<model.getRowCount();i++){
            for(int j=0;j<model.getColumnCount();j++)
                rowData[j]=model.getValueAt(i, j).toString();
            brands.add(rowData[1]);
            models.add(rowData[2]);
            quantities.add(Integer.parseInt(rowData[3]));
            prices.add(Float.parseFloat(rowData[4]));
        }
    }
    private int getDayDiff(int year1, int month1, int day1, int year2, int month2, int day2){
        int dayDiff;
        int monthDiff;
        int yearDiff;
        if(day1<day2){
            day1+=30;
            month1-=1;
        }
        dayDiff=day1-day2;
        if(month1<month2){
            month1+=12;
            year1-=1;
        }
        monthDiff=month1-month2;
        yearDiff=year1-year2;
        dayDiff=yearDiff*12*30+monthDiff*30+dayDiff;
        return dayDiff;
    }
private void removeModelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeModelActionPerformed
        if(tableTRECustomerOrders.isEditing())
            JOptionPane.showMessageDialog(null, "Can't remove while editing a cell!");
        else if(tableTRECustomerOrders.getSelectedRow() == -1)
            JOptionPane.showMessageDialog(null, "Nothing selected!");
        else{
            installationIDs.remove(tableTRECustomerOrders.getSelectedRow());
            model.removeRow(tableTRECustomerOrders.getSelectedRow());
            nRows--;
        }
        tableTRECustomerOrders.setModel(model);
}//GEN-LAST:event_removeModelActionPerformed

private void addModelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addModelActionPerformed
        Object[] rowData=new Object[4];
        rowData[1]=cbxTREBrand.getSelectedItem();
        rowData[2]=listTREUnits.getSelectedValue();
        try{
            rowData[2].toString().equals(null);
        }
        catch(Exception e){
            rowData[2]=installations.get(0).getModel();
        }
        model.insertRow(nRows,rowData);
        nRows++;
        tableTRECustomerOrders.setModel(model);
        try{
            installationIDs.add(installations.get(listTREUnits.getSelectedIndex()).getInstallationID());
        }
        catch(Exception e){
            installationIDs.add(installations.get(0).getInstallationID());
        }
}//GEN-LAST:event_addModelActionPerformed

private void saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveActionPerformed
        releaseQuery=new TransactionReleaseQuery(conn);
        if(tableTRECustomerOrders.isEditing())
            JOptionPane.showMessageDialog(null, "Can't save while editing a cell!");
        else if(!validTable() || tableIsEmpty())
            JOptionPane.showMessageDialog(null, "All fields cannot be empty!");
        else if(datePicker.getDate().after(date))
            JOptionPane.showMessageDialog(null, "Stay on the current time!");
        else if(getDayDiff(date.getYear(),date.getMonth(),date.getDate(),datePicker.getDate().getYear(),datePicker.getDate().getMonth(),datePicker.getDate().getDate())>180)
            JOptionPane.showMessageDialog(null, "Stay on the current time!");
        else{
            JOptionPane pane=new JOptionPane("Are you sure you want to add this release?");
            Object[] options=new String[]{"Yes","No"};
            pane.setOptions(options);
            JDialog dialog = pane.createDialog(new JFrame(), "Confirm Release Addition");
            dialog.show();
            if(options[0].equals(pane.getValue())){
                getTableValues();
                releaseQuery.editRelease(Integer.parseInt(txtTREOrderID.getText()),customerID,txtTRECustomer.getText(),datePicker.getDate(),cbxTREStatus.getSelectedItem().toString(),serialNumbers,quantities,prices,installationIDs,brands,models,origSerialNumbers);
                backToMainMenu=true;
            } //YES
        }
}//GEN-LAST:event_saveActionPerformed

private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
        JOptionPane pane=new JOptionPane("Are you sure you want to go back to the main menu? Please make sure that all changes have been saved.");
        Object[] options=new String[]{"Yes","No"};
        pane.setOptions(options);
        JDialog dialog = pane.createDialog(new JFrame(), "Back To Main Menu?");
        dialog.show();
        if(options[0].equals(pane.getValue())) //YES
            backToMainMenu=true;
}//GEN-LAST:event_cancelActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnTREAdd;
    private javax.swing.JButton btnTRECancel;
    private javax.swing.JButton btnTRERemove;
    private javax.swing.JButton btnTRESave;
    private javax.swing.JComboBox cbxTREBrand;
    private javax.swing.JComboBox cbxTREStatus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList listTREUnits;
    private javax.swing.JTable tableTRECustomerOrders;
    private javax.swing.JTextField txtTRECustomer;
    private javax.swing.JTextField txtTREOrderID;
    // End of variables declaration//GEN-END:variables
}
